package com.atldy.commerce.controller;

import com.atldy.commerce.async.impl.AsyncTaskManager;
import com.atldy.commerce.commence.goods.GoodsInfo;
import com.atldy.commerce.vo.AsyncTaskInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version 1.0
 * @Author: li-dong-yang
 * @CreateTime: 2021-08-21 21:45
 * @Description： 异步服务接口
 */
@Api(value = "异步服务接口", description = "异步服务接口")
@RequestMapping("/async")
@RestController
public class AsyncController {

    @Autowired
    private AsyncTaskManager asyncTaskManager;

    @ApiOperation(value = "异步进行商品入库", notes = "异步进行商品入库")
    @PostMapping("/addGoods")
    public AsyncTaskInfo addGoods(@RequestBody List<GoodsInfo> goodsInfos) {
        return asyncTaskManager.submit(goodsInfos);
    }

    @ApiOperation(value = "根据任务id查询异步任务信息", notes = "根据任务id查询异步任务信息")
    @GetMapping("/getAsyncTaskInfo")
    public AsyncTaskInfo getAsyncTaskInfo(String taskId) {
        return asyncTaskManager.getAsyncTaskInfo(taskId);
    }

}